import { topCategory } from "@/api/constants"
import { findAllCategory } from "@/api/category"
export default {
    namespaced: true,
    // 写成函数 vue3
    state() {
        return {
            list: topCategory.map(item => ({
                name: item
            }))
        }
    },
    mutations: {
        setList(state, headCategory) {
            state.list = headCategory

        },
        show(state, id) {
            const curreCategory = state.list.find(item => item.id === id)
            curreCategory.open = true
        },
        hide(state, id) {
            const curreCategory = state.list.find(item => item.id === id)
            curreCategory.open = false
        }
    },
    actions: {
        async getlist({ commit }) {

            const { result } = await findAllCategory()
            result.forEach(top => top.open = false)
            commit('setList', result)

        }
    }
}